<?php
include_once('common/header.php');
if($AppUI->id <= 0 || (isset($_SESSION['content']) && (($_SESSION['content']&1<<1) == 0)) || $AppUI->type < 2) {
	$this->_redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : HOST_BACKEND);
}
$intLanguage	= $objRequest->getParam('planguage', LANGUAGE_VN);
$strPage		= $objRequest->getParam('ppage', '');
$strSection		= $objRequest->getParam('psection', '');
$strName		= $objRequest->getParam('pname', '');
$strContent		= $objRequest->getParam('pcontent', '');
$oFile			= $_FILES['pimage'];
$arrErr			= null;
$strImage		= '';
$strName		= Ecore_Function::stripTags($strName,-2);
$strContent		= Ecore_Function::stripTags($strContent,5);
if($strPage == '') $arrErr[] = $arrLocale['page_required'];
elseif($strPage != '' && strlen($strPage) < VL_NAME_MINLENGTH) $arrErr[] = $arrLocale['page_minlength'];
elseif($strPage != '' && !Ecore_Function::isValidCode($strPage)) $arrErr[] = $arrLocale['page_format'];
if($strName == '') $arrErr[] = $arrLocale['name_required'];
elseif($strName != '' && strlen($strName) < VL_NAME_MINLENGTH) $arrErr[] = $arrLocale['name_required'];
if($strContent == '') $arrErr[] = $arrLocale['content_required'];
elseif($strContent != '' && strlen(strip_tags($strContent)) < VL_CONTENT_MINLENGTH) $arrErr[] = $arrLocale['content_minlength'];
if(!isset($arrErr) && isset($oFile)) {
	$arrImage	= Ecore_Upload_Other::upload($oFile);
	if($arrImage['error'] == 0) {
		$strImage	= $arrImage['path'];
	}else {
		$arrErr[] = $arrError['upload'];
	}
}
if(!isset($arrErr)) {
	if(isset($_SESSION['CONTENT_POST'])) unset($_SESSION['CONTENT_POST']);
	if(isset($_SESSION['CONTENT_ERROR'])) unset($_SESSION['CONTENT_ERROR']);
	$objContent = new Content();	
	$intError	= $objContent->add($AppUI->id, $intLanguage, $strPage, $strSection, $strName, $strContent, $strImage);
	if($intError == 0) {
		Ecore_Function::setMsg($arrMessage['content_add']);
		
	}
}
if(isset($arrErr)) {
	$_SESSION['CONTENT_POST']	= $objRequest->getParams();
	$_SESSION['CONTENT_ERROR']	= $arrErr;
	$this->_redirect(HOST_BACKEND . 'content/add');
}
$this->_redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : HOST_BACKEND);